package com.lagou.server;

import com.lagou.model.TestMessage;
import com.lagou.model.User;
import com.lagou.model.UserMessage;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * 编程实现数据的存取
 */
public class ServerDao {
    private HashMap<String, String> testSet = new HashMap<>();
    private LinkedList<User> studentSet = new LinkedList<>();

    public HashMap<String, String> getTestSet() {
        return testSet;
    }

    public void setTestSet(HashMap<String, String> testSet) {
        this.testSet = testSet;
    }

    public LinkedList<User> getStudentSet() {
        return studentSet;
    }

    public void setStudentSet(LinkedList<User> studentSet) {
        this.studentSet = studentSet;
    }

    /**
     * 编程实现管理员账号和密码的校验并将结果返回出去
     * @param user
     * @return
     */
    public boolean serverManagerCheck(User user) {
        if ("admin".equals(user.getUserName()) && "123456".equals(user.getPassword())) {
            return true;
        }
        return false;
    }

    public boolean serverStudentCheck(User user) {
        if (studentSet.contains(user) ) {
            return true;
        }
        return false;
    }

    public boolean passwordCheck(UserMessage usm) {
        if (!"".equals(usm.getUser().getPassword())) {
            return true;
        }
        return false;
    }

    public boolean testStartCheck(UserMessage usm) {
        if (studentSet.contains(usm.getUser())) {
                return true;
        }
        return false;
    }

    public boolean getScoreCheck(UserMessage usm){
        if (studentSet.contains(usm.getUser())) {
            return true;
        }
        return false;
    }

    public boolean addStudentCheck(UserMessage tum){
        if (!studentSet.contains(tum.getUser())) {
            return true;
        }
        return false;
    }

    public boolean deleteStudentCheck(UserMessage tum){
        if (studentSet.contains(tum.getUser())) {
            return true;
        }
        return false;
    }

    public boolean modifyStudentCheck(UserMessage tum){
        if (studentSet.contains(tum.getUser())) {
            return true;
        }
        return false;
    }

    public boolean searchStudentCheck(UserMessage tum){
        if ( studentSet.contains(tum.getUser())) {
            return true;
        }
        return false;
    }

    public boolean addTestCheck(TestMessage ttm){
        if ( !testSet.containsKey(ttm.getTest().getQuestion())) {
            testSet.put(ttm.getTest().getQuestion(), ttm.getTest().getAnswer());
            return true;
        }
        return false;
    }

    public boolean deleteTestCheck(TestMessage ttm){
        if (testSet.containsKey(ttm.getTest().getQuestion())) {
            testSet.remove(ttm.getTest().getQuestion());
            return true;
        }
        return false;
    }

    public boolean modifyTestCheck(TestMessage ttm){
        if ( testSet.containsKey(ttm.getTest().getQuestion())) {
            return true;
        }
        return false;
    }

    public boolean searchTestCheck(TestMessage ttm){
        if ( testSet.containsKey(ttm.getTest().getQuestion())) {
            return true;
        }
        return false;
    }
}
